<template>
  <div>
    标题：<input type="text" v-model="postObj.title"><br>
    内容：<textarea v-model="postObj.content"></textarea><br>
    <input type="button" value="发表" @click="addPost()">
    <input type="button" value="重置" @click="postObj={}">
    <input type="button" value="返回" @click="back()">{{ postObj }}
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      postObj: {}
    }
  }, created() {
    this.postObj.channelId = this.$route.query.channelId
  }, methods: {
    addPost() {
      axios.get("/project/post/add", {
        params: this.postObj
      }).then(resp => {
        alert();
        if (resp.data == "ok") {
          this.$router.push({name: "Post", query: {channelId: this.postObj.channelId}});
        }
      })
    },
    back() {
      this.$router.push({name: "Post", query: {channelId: this.postObj.channelId}});
    }
  }
}
</script>

<style scoped>

</style>